<template>
  <div>
    <el-dialog :title="title" :visible.sync="dialogVisible">
      <el-form ref="form" :model="form" :rules="rules">
        <el-form-item label="车辆名称" :label-width="formLabelWidth" prop="car_name">
          <el-input v-model="form.car_name" />
        </el-form-item>
        <el-form-item label="车牌号" :label-width="formLabelWidth" prop="car_num">
          <el-input v-model="form.car_num" />
        </el-form-item>
        <el-form-item label="乘坐人数" :label-width="formLabelWidth" prop="limit">
          <el-input v-model="form.limit" />
        </el-form-item>
        <el-form-item label="收费标准" :label-width="formLabelWidth" prop="integral">
          <el-input v-model="form.integral" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitFun('form')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { uploadCarInfoApi } from '@/api/main'
export default {
  data() {
    return {
      title: '新增',
      dialogVisible: false,
      upType: 1,
      form: {
        car_name: '',
        car_num: '',
        id: '',
        limit: '',
        integral: ''
      },
      rules: {
        car_name: [
          { required: true, message: '请输入车辆名称', trigger: 'blur' }
        ],
        car_num: [
          { required: true, message: '请输入车辆牌照', trigger: 'blur' }
        ],
        limit: [
          { required: true, message: '请输入车辆可乘人数', trigger: 'blur' }
        ],
        integral: [
          { required: true, message: '请输入车辆费用', trigger: 'blur' }
        ]
      },
      formLabelWidth: '120px'
    }
  },
  created() {
  },
  methods: {
    submitFun(formname) {
      this.$refs[formname].validate((valid) => {
        if (valid) {
          const data = {
            type: this.upType,
            car_name: this.form.car_name,
            car_num: this.form.car_num,
            limit: this.form.limit,
            integral: this.form.integral,
            id: this.form.id
          }
          uploadCarInfoApi(data).then(res => {
            if (res.code === 200) {
              this.$message.success(res.msg)
              this.dialogVisible = false
              this.$emit('reloadFun')
            } else {
              this.$message.error(res.msg)
            }
          })
        }
      })
    }
  }

}
</script>

<style lang="scss" scoped>
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
  .red {
    color: red;
  }
  .span {
    color: #ccc;
    font-size: 12px;
  }
</style>
